#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>

int g_val_1;
int g_val_2=100;

int main()
{
	printf("code addr: %p\n",main);
	const char*str="hello str";
	printf("read only string addr: %p\n",str);
	printf("init global value addr:%p\n",g_val_2);
	printf("uninit global value addr:%p\n",&g_val_1);
	char *mem=(char*)malloc(100);
	printf("heap addr:%p\n",mem);
	printf("stack add:%p\n",&str);
	// fork函数创建进程，将子进程pid返回给父进程，给子进程返回0
	/*
	pid_t id=fork();
	while(1)
	{
		if(id==0)
		{
			int cnt=0;
			//printf("我是子进程，PID=%d\n",getpid());
			while(cnt<=5)
			{
				printf("我是子进程，PID=%d\n",getpid());
				cnt++;
				sleep(1);
			}
			exit(0);
		}
		else if(id>0)
		{
			printf("我是父进程，PID=%d\n",getppid());
		}
		else
		{
			printf("error\n");
		}
		sleep(1);
	}*/
	/*pid_t id=getpid();
	while(1)
	{
		printf("我是一个进程,PID:%d\n",id);
		sleep(1);
	}*/
	return 0;
}
